package com.briup.jd2407cms.web.controller;

import com.briup.jd2407cms.domain.LoginParam;
import com.briup.jd2407cms.domain.User;
import com.briup.jd2407cms.result.Result;
import com.briup.jd2407cms.service.UserService;
import com.briup.jd2407cms.utils.JwtUtil;
import com.briup.jd2407cms.utils.MD5Utils;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.Map;

/**
 * @BelongsProject: cms2
 * @BelongsPackage: com.briup.jd2407cms.web.controller
 * @Author: wangjie
 * @CreateTime: 2024-11-20  09:19
 * @Description: TODO
 * @Version: 1.0
 */
@Api(tags = "登录模块")
@RestController
public class LoginController {
    @Autowired
    UserService userService;
    @ApiOperation("登录")
    @ApiImplicitParam(name = "loginParam",value = "登陆参数，账号对象",required = true)
    @PostMapping("/login")
    private Result login(@RequestBody LoginParam loginParam){
        User login = userService.login(loginParam.getUsername(), MD5Utils.MD5(loginParam.getPassword()));
        Map<String,Object> map = new HashMap<>();
        map.put("userId",login.getId());
        map.put("username",login.getUsername());
        map.put("isVip",login.getIsVip());
        map.put("roleId",login.getRoleId());
        String token = JwtUtil.generateJwt(map);

        return Result.success(token);
    }
    @ApiOperation("退出")
    @PostMapping("/logout")
    private Result logout(){
        return Result.success();
    }

}
